package com.company.beauty.sms.config;

import com.company.beauty.sms.config.properties.AliyunSmsProperties;
import com.company.pangu.aliyun.sms.client.SmsClient;
import com.company.pangu.aliyun.sms.config.SmsConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;

/**
 * <p>sms auto configuration</p >
 *
 * @author youyoukele
 * @version 1.0
 * @date 2024/04/22
 */
@Slf4j
@Import({AliyunSmsProperties.class})
@Configuration(proxyBeanMethods = false)
public class AliyunSmsConfiguration {

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "aliyun.sms", name = "enabled", havingValue = "true", matchIfMissing = false)
    public SmsClient aliyunSmsClient(AliyunSmsProperties properties) {
        SmsConfig config = SmsConfig.builder()
                .accessKeyId(properties.getAccessKeyId())
                .accessKeySecret(properties.getAccessKeySecret())
                .endPoint(properties.getEndPoint())
                .build();
        log.info("nasa3 sms starter load aliyun sms client");
        return new SmsClient(config);
    }

}
